<?php

namespace User\Controller;
use Common\Controller\MemberbaseController;
class WeixinController extends MemberbaseController {
	
	protected $db;
	function _initialize(){
		parent::_initialize();
		
		vendor('weixin.JsApiPay');
		vendor('weixin.WxPayConfig');
		vendor('weixin.WxPayApi');
		vendor('weixin.PayNotifyCallBack');
		
	}
	function printf_info($data)
	{
		foreach($data as $key=>$value){
			echo "<font color='#00ff55;'>$key</font> : $value <br/>";
		}
		}
    
    public function pay() {
    		$order_sn=I('get.order_sn');
    		
    		if(!$order_sn) $this->error("缺少参数");
    		
    	$info=D("Order")->where(array("order_sn"=>$order_sn))->find();


		$sj_price=$info['price_sum'];



		// /①、获取用户openid
		$tools = new \JsApiPay ();
		$openId = session("open_id");
		
		// ②、统一下单
		$input = new \WxPayUnifiedOrder ();

		$input->SetOut_trade_no ( $order_sn );
		$input->SetTotal_fee ( $sj_price*100 );
		$input->SetTime_start ( date ( "YmdHis" ) );
		$input->SetTime_expire ( date ( "YmdHis", time () + 600 ) );

		$input->SetBody ($info["title"] );

		$input->SetNotify_url ( "http://jhlmall.com/Home/Weixin/notify" );
		$input->SetTrade_type ( "JSAPI" );
		$input->SetOpenid ( $openId );
		$order = \WxPayApi::unifiedOrder ( $input );





		$this->assign("info",$info);
		$jsApiParameters = $tools->GetJsApiParameters ( $order );


    	
    	$this->assign('jsApiParameters',$jsApiParameters);


		if($info[modal]=="chongzhi"){


			$this->display('chongzhi');


		}elseif($info[modal]=="product"){
			$this->display('');
		}
		elseif($info[modal]=="huodong"){
			$this->display('huodong');
		}


    	//echo $jsApiParameters;
    
   
    	
    }




    
    
	}
 ?>